package com.jessechanrui.template.projectcase.interfaces.demo.http;

import com.jessechanrui.template.projectcase.application.DemoAppService;
import com.jessechanrui.template.projectcase.application.dto.DemoDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author chenrui
 * @date 2024/1/30
 */
@RestController
@Api(tags = "示例接口")
@RequestMapping("/demo")
@Validated
public class DemoController {

    @Autowired
    private DemoAppService demoAppService;

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public DemoDTO save(@RequestBody @Valid DemoDTO demoDTO) {
        return demoAppService.saveData(demoDTO);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "根据ID获取")
    public DemoDTO get(@PathVariable("id") Integer id) {
        return demoAppService.getById(id);
    }

    @GetMapping("/getAll")
    @ApiOperation(value = "查询全量")
    public List<DemoDTO> findAll() {
        return demoAppService.findAll();
    }
}
